#include<stdio.h>
#include<string.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<unistd.h>
#include<string.h>

int main()
{

    //printf("%d\n", stdin->_fileno);
    //printf("%d\n", stdout->_fileno);
    //printf("%d\n", stderr->_fileno);

    //char s[20];
    //fscanf(stdin, "%s", s);
    //printf("%s\n", s);
    //fprintf(stdout, "snowdragon writed\n");

    umask(0);
    int fd1 = open("log1.txt", O_WRONLY | O_CREAT | O_TRUNC, 0666);
    printf("fd1:%d\n", fd1);
    int fd2 = open("log2.txt", O_WRONLY | O_CREAT | O_TRUNC, 0666);
    printf("fd2:%d\n", fd2);
    int fd3 = open("log3.txt", O_WRONLY | O_CREAT | O_TRUNC, 0666);
    printf("fd3:%d\n", fd3);
    close(fd1);
    close(fd2);
    close(fd3);

    //umask(0);
    ////int fd = open("log.txt", O_WRONLY | O_CREAT | O_TRUNC, 0666);
    ////int fd = open("log.txt", O_WRONLY | O_CREAT | O_APPEND, 0666);
    //int fd = open("log.txt", O_RDONLY);
    ////char s[] = "snowdraon writed\n";
    ////write(fd, s, strlen(s));
    //

    //char buffer[30];
    //ssize_t ret = read(fd, buffer, sizeof buffer);      //ret的类型是ssize_t,不是int
    //if(ret > 0 )
    //{
    //    buffer[ret] = '\0';
    //}
    //printf("%s\n",buffer);

    return 0;
}


//#define ONE 0x1         //0x1后面不能加分号;否则下方的操作会因为多了一个;而出错
//#define TWO 0x2
//#define THREE 0x4
//
//void show(int num)
//{
//    if(num & ONE) printf("ONE\n");
//    if(num & TWO) printf("TWO\n");
//    if(num & THREE) printf("THREE\n");
//}
//
//int main()
//{
//    show(ONE);
//    printf("--------------------\n");
//    show(TWO);
//    printf("--------------------\n");
//    show(THREE);
//    printf("--------------------\n");
//    show(ONE | TWO | THREE);
//    printf("--------------------\n");
//    show(ONE | THREE);
//    return 0;
//}
//

//int main()
//{
//    FILE* fp = fopen("log.txt", "r");
//    char line[20];
//    fgets(line, sizeof line, fp);
//    printf("%s\n", line);
//
//    //FILE* fp = fopen("log.txt", "w");
//    //if(fp == NULL)
//    //{
//    //    perror("fopen");
//    //    return 1;
//    //}
//    //char arr1[] = "fwrite writed\n";
//    //fwrite(arr1, strlen(arr1), 1, fp);
//
//    //fprintf(fp, "fprintf wirted\n");
//    //char arr2[] = "fpushs writed\n";
//    //fputs(arr2, fp);
//    //
//    //fclose(fp);
//
//    return 0;
//}
